package com.xjc.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjc.business.entity.domain.*;
import com.xjc.business.entity.po.classadmin.ClassAdminLeaveApplyOpera;
import com.xjc.business.entity.po.stu.LeaveApplyPo;
import com.xjc.business.entity.vo.PageVo;
import com.xjc.business.entity.vo.classadmin.ClassLeaveApplyVo;
import com.xjc.business.entity.vo.dooradmin.StuLeaveApplyDetailsVo;
import com.xjc.business.entity.vo.stu.HistoryLeaveApplyVo;
import com.xjc.business.entity.vo.stu.LeaveApplyVo;
import com.xjc.business.service.*;
import com.xjc.business.mapper.StudentLeaveApplysMapper;
import com.xjc.system.result.Result;
import com.xjc.system.utils.ImageToBase64Utils;
import com.xjc.system.utils.QRCodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author root
* @description 针对表【student_leave_applys(学生请假申请表)】的数据库操作Service实现
* @createDate 2025-01-25 10:24:32
*/
@Service
public class StudentLeaveApplysServiceImpl extends ServiceImpl<StudentLeaveApplysMapper, StudentLeaveApplys>
    implements StudentLeaveApplysService {

    @Autowired
    @Lazy
    WxUserService wxUserService;

    @Autowired
    @Lazy
    AllStudentRegsiterRelationsService allStudentRegsiterRelationsService;

    @Autowired
    @Lazy
    ClassAdminRelationsService classAdminRelationsService;

    @Autowired
    @Lazy
    ClassAdminsService classAdminsService;

    @Autowired
    @Lazy
    StudentsService studentsService;

    @Autowired
    @Lazy
    ClazzsService clazzsService;

    @Autowired
    @Lazy
    MajorsService majorsService;

    @Autowired
    @Lazy
    CollageAdminRelationsService collageAdminRelationsService;

    /**
     * 获取当前学生的请假申请
     *
     * @param id 微信Id
     * @return Result
     */
    @Override
    public Result<LeaveApplyVo> getCurrentLeaveApply(Integer id) {
        Integer stuId = wxUserService.getById(id).getStuId();

        LambdaQueryWrapper<StudentLeaveApplys> studentLeaveApplysLambdaQueryWrapper = new LambdaQueryWrapper<>();
        studentLeaveApplysLambdaQueryWrapper.eq(StudentLeaveApplys::getStuId,stuId);
        studentLeaveApplysLambdaQueryWrapper.in(StudentLeaveApplys::getStatus,0,2); // 使用中或者审核中

        StudentLeaveApplys studentLeaveApplys = this.getOne(studentLeaveApplysLambdaQueryWrapper);
        if (studentLeaveApplys == null){
            return Result.okWithData(null);
        }

        LeaveApplyVo leaveApplyVo = new LeaveApplyVo();
        leaveApplyVo.setId(studentLeaveApplys.getId());
        leaveApplyVo.setType(studentLeaveApplys.getType());
        leaveApplyVo.setReason(studentLeaveApplys.getReason());
        leaveApplyVo.setPics(studentLeaveApplys.getPics());
        leaveApplyVo.setDest(studentLeaveApplys.getDest());
        leaveApplyVo.setTrancType(studentLeaveApplys.getTrancType());
        leaveApplyVo.setTrancCard(studentLeaveApplys.getTrancCard());
        leaveApplyVo.setPhone(studentLeaveApplys.getPhone());
        leaveApplyVo.setStartTime(studentLeaveApplys.getStartTime());
        leaveApplyVo.setEndTime(studentLeaveApplys.getEndTime());
        leaveApplyVo.setClassAdminStatus(studentLeaveApplys.getClassAdminStatus());
        leaveApplyVo.setCollegeAdminStatus(studentLeaveApplys.getCollegeAdminStatus());
        leaveApplyVo.setStatus(studentLeaveApplys.getStatus());
        leaveApplyVo.setClassAdminInfo(studentLeaveApplys.getClassAdminInfo());
        leaveApplyVo.setCollegeAdminInfo(studentLeaveApplys.getCollegeAdminInfo());
        leaveApplyVo.setCreateTime(studentLeaveApplys.getCreateTime());
        leaveApplyVo.setAccompanyingPerson(studentLeaveApplys.getAccompanyingPerson());
        leaveApplyVo.setAccompanyingPersonPhone(studentLeaveApplys.getAccompanyingPersonPhone());

        return Result.okWithData(leaveApplyVo);
    }

    /**
     * 添加请假申请
     * @param leaveApplyPo 请假申请
     * @return Result
     */
    @Override
    public Result<String> addLeaveApply(LeaveApplyPo leaveApplyPo) {
        Integer wxId = leaveApplyPo.getId();
        Integer stuId = wxUserService.getById(wxId).getStuId();

        LambdaQueryWrapper<AllStudentRegsiterRelations> allStudentRegsiterRelationsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        allStudentRegsiterRelationsLambdaQueryWrapper.eq(AllStudentRegsiterRelations::getStuId,stuId);
        AllStudentRegsiterRelations studentFromDB = allStudentRegsiterRelationsService.getOne(allStudentRegsiterRelationsLambdaQueryWrapper);
        Integer clazzId = studentFromDB.getClazzId();

        LambdaQueryWrapper<ClassAdminRelations> classAdminRelationsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        classAdminRelationsLambdaQueryWrapper.eq(ClassAdminRelations::getClId,clazzId);
        ClassAdminRelations classAdminRelations = classAdminRelationsService.getOne(classAdminRelationsLambdaQueryWrapper);
        Integer clazzAdminId = classAdminRelations.getClazzAdminId();

        StudentLeaveApplys studentLeaveApplys = new StudentLeaveApplys();
        studentLeaveApplys.setStuId(stuId);
        studentLeaveApplys.setType(leaveApplyPo.getType());
        studentLeaveApplys.setReason(leaveApplyPo.getReason());
        studentLeaveApplys.setPics(leaveApplyPo.getPics());
        studentLeaveApplys.setDest(leaveApplyPo.getDest());
        studentLeaveApplys.setTrancType(leaveApplyPo.getTrancType());
        studentLeaveApplys.setTrancCard(leaveApplyPo.getTrancCard());
        studentLeaveApplys.setPhone(leaveApplyPo.getPhone());
        studentLeaveApplys.setStartTime(leaveApplyPo.getStartTime());
        studentLeaveApplys.setEndTime(leaveApplyPo.getEndTime());
        studentLeaveApplys.setClassAdminAuditorId(clazzAdminId);
        studentLeaveApplys.setStatus(2);
        studentLeaveApplys.setCreateTime(new Date());
        studentLeaveApplys.setUpdateTime(new Date());
        studentLeaveApplys.setAccompanyingPerson(leaveApplyPo.getAccompanyingPerson());
        studentLeaveApplys.setAccompanyingPersonPhone(leaveApplyPo.getAccompanyingPersonPhone());
        save(studentLeaveApplys);
        return Result.okWithData("添加成功");
    }

    /**
     * 获取请假申请列表
     * @param pageSize     每页显示条数
     * @param currentPage  当前页
     * @param classAdminId 辅导员id
     * @param status       状态
     * @param stuName      学生姓名
     * @return Result
     */
    @Override
    public Result<PageVo<ClassLeaveApplyVo>> getLeaveApplyPage(Integer pageSize, Integer currentPage, Integer classAdminId, Integer status, String stuName) {

        LambdaQueryWrapper<ClassAdminRelations> classAdminRelationsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        classAdminRelationsLambdaQueryWrapper.eq(ClassAdminRelations::getClazzAdminId,classAdminId);
        List<Integer> classIdList = classAdminRelationsService.list(classAdminRelationsLambdaQueryWrapper).stream().map(ClassAdminRelations::getClId).collect(Collectors.toList());

        if(classIdList.isEmpty()){
            return Result.okWithData(new PageVo<>());
        }

        LambdaQueryWrapper<AllStudentRegsiterRelations> allStudentRegsiterRelationsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        allStudentRegsiterRelationsLambdaQueryWrapper.in(AllStudentRegsiterRelations::getClazzId,classIdList);
        List<Integer> stuIdList = allStudentRegsiterRelationsService.list(allStudentRegsiterRelationsLambdaQueryWrapper).stream().map(AllStudentRegsiterRelations::getStuId).collect(Collectors.toList());

        LambdaQueryWrapper<Students> studentsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        studentsLambdaQueryWrapper.like(Students::getName, stuName);
        List<Integer> collect = studentsService.list(studentsLambdaQueryWrapper).stream().map(Students::getId).collect(Collectors.toList());
        stuIdList.retainAll(collect);

        if(stuIdList.isEmpty()){
            return Result.okWithData(new PageVo<>());
        }

        LambdaQueryWrapper<StudentLeaveApplys> studentLeaveApplysLambdaQueryWrapper = new LambdaQueryWrapper<>();
        studentLeaveApplysLambdaQueryWrapper.in(StudentLeaveApplys::getStuId,stuIdList);
        studentLeaveApplysLambdaQueryWrapper.eq(status!=-1,StudentLeaveApplys::getClassAdminStatus,status);

        Page<StudentLeaveApplys> studentLeaveApplysPage = new Page<>(currentPage, pageSize);
        page(studentLeaveApplysPage,studentLeaveApplysLambdaQueryWrapper);
        List<StudentLeaveApplys> studentLeaveApplysPageRecords = studentLeaveApplysPage.getRecords();

        List<ClassLeaveApplyVo> classLeaveApplyVoList = studentLeaveApplysPageRecords.stream().map(studentLeaveApplys -> {
            ClassLeaveApplyVo classLeaveApplyVo = new ClassLeaveApplyVo();
            classLeaveApplyVo.setId(studentLeaveApplys.getId());
            classLeaveApplyVo.setStuName(studentsService.getById(studentLeaveApplys.getStuId()).getName());
            Integer stuId = studentLeaveApplys.getStuId();
            LambdaQueryWrapper<AllStudentRegsiterRelations> allStudentRegsiterRelationsLambdaQueryWrapper2 = new LambdaQueryWrapper<>();
            allStudentRegsiterRelationsLambdaQueryWrapper2.eq(AllStudentRegsiterRelations::getStuId,stuId);
            AllStudentRegsiterRelations studentFromDB = allStudentRegsiterRelationsService.getOne(allStudentRegsiterRelationsLambdaQueryWrapper2);
            Integer classId = studentFromDB.getClazzId();
            Integer majId = studentFromDB.getMajId();
            classLeaveApplyVo.setClassName(majorsService.getById(majId).getName()+clazzsService.getById(classId).getNum()+"班");
            classLeaveApplyVo.setType(studentLeaveApplys.getType());
            classLeaveApplyVo.setReason(studentLeaveApplys.getReason());
            classLeaveApplyVo.setPics(studentLeaveApplys.getPics());
            classLeaveApplyVo.setDest(studentLeaveApplys.getDest());
            classLeaveApplyVo.setTrancType(studentLeaveApplys.getTrancType());
            classLeaveApplyVo.setTrancCard(studentLeaveApplys.getTrancCard());
            classLeaveApplyVo.setPhone(studentLeaveApplys.getPhone());
            classLeaveApplyVo.setAccompanyingPerson(studentLeaveApplys.getAccompanyingPerson());
            classLeaveApplyVo.setAccompanyingPersonPhone(studentLeaveApplys.getAccompanyingPersonPhone());
            classLeaveApplyVo.setStartTime(studentLeaveApplys.getStartTime());
            classLeaveApplyVo.setEndTime(studentLeaveApplys.getEndTime());
            classLeaveApplyVo.setClassAdminStatus(studentLeaveApplys.getClassAdminStatus());
            classLeaveApplyVo.setCollegeAdminStatus(studentLeaveApplys.getCollegeAdminStatus());
            classLeaveApplyVo.setStatus(studentLeaveApplys.getStatus());
            classLeaveApplyVo.setClassAdminInfo(studentLeaveApplys.getClassAdminInfo());
            classLeaveApplyVo.setCollegeAdminInfo(studentLeaveApplys.getCollegeAdminInfo());
            classLeaveApplyVo.setCreateTime(studentLeaveApplys.getCreateTime());
            return classLeaveApplyVo;
        }).collect(Collectors.toList());
        PageVo<ClassLeaveApplyVo> pageVo = new PageVo<>();
        pageVo.setData(classLeaveApplyVoList);
        pageVo.setTotal(studentLeaveApplysPage.getTotal());
        pageVo.setPageCount(studentLeaveApplysPage.getPages());
        pageVo.setCurrent(currentPage);
        pageVo.setSize(pageSize);

        return Result.okWithData(pageVo);
    }

    /**
     * 辅导员审批请假申请
     * @param classAdminLeaveApplyOpera 审批意见
     * @return Result
     */
    @Override
    public Result<String> leaveApplyOpera(ClassAdminLeaveApplyOpera classAdminLeaveApplyOpera) {
        Integer id = classAdminLeaveApplyOpera.getId();
        StudentLeaveApplys studentLeaveApplys = getById(id);
        studentLeaveApplys.setClassAdminStatus(classAdminLeaveApplyOpera.getClassAdminStatus());
        studentLeaveApplys.setClassAdminInfo(classAdminLeaveApplyOpera.getClassAdminInfo());

        updateById(studentLeaveApplys);
        return Result.okWithData("审批完成");
    }

    /**
     * 获取请假申请列表
     * @param pageSize       每页显示条数
     * @param currentPage    当前页
     * @param collegeAdminId 学院管理员id
     * @param status         状态
     * @param stuName        学生姓名
     * @return Result
     */
    @Override
    public Result<PageVo<ClassLeaveApplyVo>> getLeaveApplyPage2(Integer pageSize, Integer currentPage, Integer collegeAdminId, Integer status, String stuName) {
        LambdaQueryWrapper<CollageAdminRelations> collageAdminRelationsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        collageAdminRelationsLambdaQueryWrapper.eq(CollageAdminRelations::getColAdminId,collegeAdminId);
        Integer colId = collageAdminRelationsService.getOne(collageAdminRelationsLambdaQueryWrapper).getColId();

        LambdaQueryWrapper<AllStudentRegsiterRelations> allStudentRegsiterRelationsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        allStudentRegsiterRelationsLambdaQueryWrapper.eq(AllStudentRegsiterRelations::getColId,colId);
        List<Integer> stuIdList = allStudentRegsiterRelationsService.list(allStudentRegsiterRelationsLambdaQueryWrapper).stream().map(AllStudentRegsiterRelations::getStuId).collect(Collectors.toList());

        LambdaQueryWrapper<Students> studentsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        studentsLambdaQueryWrapper.like(Students::getName,stuName);
        List<Integer> collectIdList = studentsService.list(studentsLambdaQueryWrapper).stream().map(Students::getId).collect(Collectors.toList());

        stuIdList.retainAll(collectIdList);

        if(stuIdList.isEmpty()){
            return Result.okWithData(new PageVo<>());
        }


        LambdaQueryWrapper<StudentLeaveApplys> studentLeaveApplysLambdaQueryWrapper = new LambdaQueryWrapper<>();
        studentLeaveApplysLambdaQueryWrapper.in(StudentLeaveApplys::getStuId,stuIdList);
        studentLeaveApplysLambdaQueryWrapper.eq(status!=-1,StudentLeaveApplys::getCollegeAdminStatus,status);
        studentLeaveApplysLambdaQueryWrapper.eq(StudentLeaveApplys::getClassAdminStatus,1);

        Page<StudentLeaveApplys> studentLeaveApplysPage = new Page<>(currentPage, pageSize);
        page(studentLeaveApplysPage,studentLeaveApplysLambdaQueryWrapper);
        List<StudentLeaveApplys> studentLeaveApplysPageRecords = studentLeaveApplysPage.getRecords();

        List<ClassLeaveApplyVo> classLeaveApplyVoList = studentLeaveApplysPageRecords.stream().map(studentLeaveApplys -> {
            ClassLeaveApplyVo classLeaveApplyVo = new ClassLeaveApplyVo();
            classLeaveApplyVo.setId(studentLeaveApplys.getId());
            classLeaveApplyVo.setStuName(studentsService.getById(studentLeaveApplys.getStuId()).getName());
            Integer stuId = studentLeaveApplys.getStuId();
            LambdaQueryWrapper<AllStudentRegsiterRelations> allStudentRegsiterRelationsLambdaQueryWrapper2 = new LambdaQueryWrapper<>();
            allStudentRegsiterRelationsLambdaQueryWrapper2.eq(AllStudentRegsiterRelations::getStuId,stuId);
            AllStudentRegsiterRelations studentFromDB = allStudentRegsiterRelationsService.getOne(allStudentRegsiterRelationsLambdaQueryWrapper2);
            Integer classId = studentFromDB.getClazzId();
            Integer majId = studentFromDB.getMajId();
            classLeaveApplyVo.setClassName(majorsService.getById(majId).getName()+clazzsService.getById(classId).getNum()+"班");
            classLeaveApplyVo.setType(studentLeaveApplys.getType());
            classLeaveApplyVo.setReason(studentLeaveApplys.getReason());
            classLeaveApplyVo.setPics(studentLeaveApplys.getPics());
            classLeaveApplyVo.setDest(studentLeaveApplys.getDest());
            classLeaveApplyVo.setTrancType(studentLeaveApplys.getTrancType());
            classLeaveApplyVo.setTrancCard(studentLeaveApplys.getTrancCard());
            classLeaveApplyVo.setPhone(studentLeaveApplys.getPhone());
            classLeaveApplyVo.setAccompanyingPerson(studentLeaveApplys.getAccompanyingPerson());
            classLeaveApplyVo.setAccompanyingPersonPhone(studentLeaveApplys.getAccompanyingPersonPhone());
            classLeaveApplyVo.setStartTime(studentLeaveApplys.getStartTime());
            classLeaveApplyVo.setEndTime(studentLeaveApplys.getEndTime());
            classLeaveApplyVo.setClassAdminStatus(studentLeaveApplys.getClassAdminStatus());
            classLeaveApplyVo.setCollegeAdminStatus(studentLeaveApplys.getCollegeAdminStatus());
            classLeaveApplyVo.setStatus(studentLeaveApplys.getStatus());
            classLeaveApplyVo.setClassAdminInfo(studentLeaveApplys.getClassAdminInfo());
            classLeaveApplyVo.setCollegeAdminInfo(studentLeaveApplys.getCollegeAdminInfo());
            classLeaveApplyVo.setCreateTime(studentLeaveApplys.getCreateTime());
            return classLeaveApplyVo;
        }).collect(Collectors.toList());
        PageVo<ClassLeaveApplyVo> pageVo = new PageVo<>();
        pageVo.setData(classLeaveApplyVoList);
        pageVo.setTotal(studentLeaveApplysPage.getTotal());
        pageVo.setPageCount(studentLeaveApplysPage.getPages());
        pageVo.setCurrent(currentPage);
        pageVo.setSize(pageSize);

        return Result.okWithData(pageVo);
    }

    /**
     * 学院管理员审批请假申请
     *
     * @param classAdminLeaveApplyOpera 审批意见
     * @return Result
     */
    @Override
    public Result<String> leaveApplyOpera2(ClassAdminLeaveApplyOpera classAdminLeaveApplyOpera) {
        Integer id = classAdminLeaveApplyOpera.getId();
        StudentLeaveApplys studentLeaveApplys = getById(id);
        studentLeaveApplys.setCollegeAdminStatus(classAdminLeaveApplyOpera.getClassAdminStatus());
        studentLeaveApplys.setCollegeAdminInfo(classAdminLeaveApplyOpera.getClassAdminInfo());
        studentLeaveApplys.setStatus(classAdminLeaveApplyOpera.getClassAdminStatus()==1?0:2);

        updateById(studentLeaveApplys);
        return Result.okWithData("审批完成");
    }

    /**
     * 出示二维码
     * @param id 请假记录Id
     * @return Result
     */
    @Override
    public Result<String> showCode(Integer id) {
        StudentLeaveApplys studentLeaveApplys = getById(id);
        String qrCodeContent = "id:" + studentLeaveApplys.getId();

        byte[] qrCodeImage = QRCodeUtil.generateQRCodeImage(qrCodeContent, 350, 350);
        String base64 = ImageToBase64Utils.encodeLocalImageToBase64(qrCodeImage);

        return Result.okWithData(base64);
    }

    /**
     * 获取请假申请详情
     * @param id 请假记录id
     * @return 请假申请详情
     */
    @Override
    public Result<StuLeaveApplyDetailsVo> getLeaveApplyDetails(Integer id) {
        StudentLeaveApplys studentLeaveApplys = getById(id);
        if(studentLeaveApplys == null){
            return Result.ok("请假记录不存在");
        }

        StuLeaveApplyDetailsVo stuLeaveApplyDetailsVo = new StuLeaveApplyDetailsVo();
        stuLeaveApplyDetailsVo.setId(studentLeaveApplys.getId());

        stuLeaveApplyDetailsVo.setStuName(studentsService.getById(studentLeaveApplys.getStuId()).getName());

        LambdaQueryWrapper<AllStudentRegsiterRelations> allStudentRegsiterRelationsLambdaQueryWrapper2 = new LambdaQueryWrapper<>();
        allStudentRegsiterRelationsLambdaQueryWrapper2.eq(AllStudentRegsiterRelations::getStuId,studentLeaveApplys.getStuId());
        AllStudentRegsiterRelations studentFromDB = allStudentRegsiterRelationsService.getOne(allStudentRegsiterRelationsLambdaQueryWrapper2);
        Integer classId = studentFromDB.getClazzId();
        Integer majId = studentFromDB.getMajId();
        stuLeaveApplyDetailsVo.setClassName(majorsService.getById(majId).getName()+clazzsService.getById(classId).getNum()+"班");

        stuLeaveApplyDetailsVo.setType(studentLeaveApplys.getType());

        stuLeaveApplyDetailsVo.setReason(studentLeaveApplys.getReason());

        stuLeaveApplyDetailsVo.setDest(studentLeaveApplys.getDest());

        stuLeaveApplyDetailsVo.setStartTime(studentLeaveApplys.getStartTime());
        stuLeaveApplyDetailsVo.setEndTime(studentLeaveApplys.getEndTime());

        stuLeaveApplyDetailsVo.setClassAdminStatus(studentLeaveApplys.getClassAdminStatus());
        stuLeaveApplyDetailsVo.setCollegeAdminStatus(studentLeaveApplys.getCollegeAdminStatus());

        stuLeaveApplyDetailsVo.setStatus(studentLeaveApplys.getStatus());

        return Result.okWithData(stuLeaveApplyDetailsVo);
    }

    /**
     * 验证请假申请
     * @param id 请假记录id
     * @return 是否验证成功
     */
    @Override
    public Result<Boolean> validateLeaveApply(Integer id) {
        StudentLeaveApplys studentLeaveApplys = getById(id);
        if(studentLeaveApplys == null){
            return Result.okWithData(false);
        }

        Integer status = studentLeaveApplys.getStatus();
        return Result.okWithData(status == 0);
    }

    /**
     * 销假
     *
     * @param id 请假记录id
     * @return 反馈
     */
    @Override
    public Result<String> changeStatus(Integer id) {
        StudentLeaveApplys studentLeaveApplys = getById(id);
        studentLeaveApplys.setStatus(1);
        updateById(studentLeaveApplys);
        return Result.okWithData("销假完成");
    }

    /**
     * 获取历史请假申请
     *
     * @param id 微信Id
     * @return Result
     */
    @Override
    public Result<List<HistoryLeaveApplyVo>> getHistoryLeaveApplyList(Integer id) {
        Integer stuId = wxUserService.getById(id).getStuId();

        LambdaQueryWrapper<StudentLeaveApplys> studentLeaveApplysLambdaQuery = new LambdaQueryWrapper<>();
        studentLeaveApplysLambdaQuery.eq(StudentLeaveApplys::getStuId,stuId);
        studentLeaveApplysLambdaQuery.eq(StudentLeaveApplys::getStatus,1);

        List<HistoryLeaveApplyVo> historyLeaveApplyVoList = list(studentLeaveApplysLambdaQuery).stream().map(studentLeaveApplys -> {
            HistoryLeaveApplyVo historyLeaveApplyVo = new HistoryLeaveApplyVo();
            historyLeaveApplyVo.setId(studentLeaveApplys.getId());
            historyLeaveApplyVo.setType(studentLeaveApplys.getType());

            historyLeaveApplyVo.setReason(studentLeaveApplys.getReason());
            historyLeaveApplyVo.setStartTime(studentLeaveApplys.getStartTime());
            historyLeaveApplyVo.setEndTime(studentLeaveApplys.getEndTime());

            return historyLeaveApplyVo;
        }).collect(Collectors.toList());

        return Result.okWithData(historyLeaveApplyVoList);
    }
}




